export interface CreateApplicantParams {
  name: string;
}

export interface CreateApplicantResponse {
  id: number;
}

export interface ApplicantItemType {
  id: number;
  name: string;
  remark: string;
}

export interface ApplicantImageType {
  id: number;
  image_url: string;
}

/**
 * @description 申请人详情
 * @property {string} 1 - 在职人员
 * @property {string} 2 - 自由职业者
 * @property {string} 3 - 退休人员
 * @property {string} 4 - 在校学生
 * @property {string} 5 - 学龄前儿童
 * @enum {string}
 */
export type ApplicantIdentityEnum = "1" | "2" | "3" | "4" | "5";

export interface ApplicantDetailType {
  id: number;
  name: string;
  identity: ApplicantIdentityEnum;
  remark: string;
  face_image_ids: ApplicantImageType[];
  passport_image_ids: ApplicantImageType[];
  idcard_image_ids: ApplicantImageType[];
  household_image_ids: ApplicantImageType[];
  marriage_image_ids: ApplicantImageType[];
  other_image_ids: ApplicantImageType[];
}

export type SupplementApplicantTypeEnum =
  | "face"
  | "passport"
  | "idcard"
  | "household"
  | "marriage"
  | "other";

export interface SupplementApplicantParams {
  id: number;
  type: SupplementApplicantTypeEnum;
  image_urls: (string | undefined)[];
}

/**
 * @description 创建申请人
 * @param {CreateApplicantParams} params
 * @returns {Promise<CreateApplicantResponse>}
 */
export function createApplicant(params: CreateApplicantParams) {
  return uni.$u.http.post<CreateApplicantResponse>(
    "/api/visa/userinfo",
    params
  );
}

/**
 * @description 获取申请人列表
 * @returns {Promise<ApplicantItemType[]>}
 */
export function getApplicantList() {
  return uni.$u.http.get<ApplicantItemType[]>("/api/visa/userinfo");
}

/**
 * @description 删除申请人
 * @param {number} id - 申请人ID
 * @returns {Promise<null>}
 */
export function deleteApplicant(id: number) {
  return uni.$u.http.delete<null>(`/api/visa/userinfo/${id}/delete`);
}

/**
 * @description 更新申请人信息
 * @param {number} id - 申请人ID
 * @param {Partial<CreateApplicantParams>} params - 更新的申请人信息
 * @returns {Promise<null>}
 */
export function getApplicantDetail(id: number) {
  return uni.$u.http.get<ApplicantDetailType>(`/api/visa/userinfo/${id}`);
}

/**
 * @description 申请人补充材料
 * @param {SupplementApplicantParams} params - 补充材料参数
 * @returns {Promise<null>}
 */
export function supplementApplicant(params: SupplementApplicantParams) {
  return uni.$u.http.post<null>(
    `/api/visa/userinfo/${params.id}/submit`,
    params
  );
}
